package com.cn.customer.housekeeping.housekeepingb.util;

import android.app.Dialog;
import android.content.Context;
import android.os.Build;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.cn.customer.housekeeping.housekeepingb.R;
import com.cn.customer.housekeeping.housekeepingb.view.LoadingDialog;



/**
 * 
 * <弹出框公共类>
 * @author caoyinfei
 * @version [版本号, 2016/6/6]
 * @see [相关类/方法]
 * @since [V1]
 */
public class DialogUtil
{
    /**
     * 获取加载等待对话框
     *
     * @param context
     * @param message
     * @param isCancelable
     * @return
     */
    public static LoadingDialog showLoadingDialog(Context context, String message, boolean isCancelable) {
        LoadingDialog dialog = new LoadingDialog(context, R.style.loading_dialog);
        //沉浸式状态栏的设置
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            Window window = dialog.getWindow();
// Translucent status bar
            window.setFlags(
                    WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
                    WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
// Translucent navigation bar
//            window.setFlags(
//                    WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION,
//                    WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        }
        dialog.setCancelable(isCancelable);
        dialog.setDlgMessage(message);
//		dialog.getWindow().setType((WindowManager.LayoutParams.TYPE_SYSTEM_ALERT));
        return dialog;
    }


    /**
     * 弹出自定义的对话框
     *
     * @param context
     * @param title
     * @param content
     * @param positiveBtnLabel
     * @param negativeBtnLabel
     * @param posLsn
     * @param ngLsn
     * @return
     */
    public static Dialog showMessageDialog(Context context,
                                           String title,
                                           String content,
                                           String positiveBtnLabel,
                                           String negativeBtnLabel,
                                           View.OnClickListener posLsn,
                                           View.OnClickListener ngLsn) {

        return showMessageDialog(context, title, content, positiveBtnLabel, negativeBtnLabel, null, posLsn, ngLsn, null);
    }

    public static Dialog showMessageDialog(Context context,
                                           String title,
                                           String content,
                                           String positiveBtnLabel,
                                           String negativeBtnLabel,
                                           String btnLabel3,
                                           View.OnClickListener posLsn,
                                           View.OnClickListener ngLsn,
                                           View.OnClickListener btn3Lsn) {
        LayoutInflater mLayoutInflater = LayoutInflater.from(context);
        View view = mLayoutInflater.inflate(R.layout.custom_msg_dlg, null);
        final Dialog dialog = new Dialog(context, R.style.kangzai_dialog);
//		dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
        dialog.setContentView(view);
        dialog.setCancelable(false);

        TextView msg_dlg_title;
        TextView msg_dlg_content;
        TextView msg_dialog_btn_cancel;
        TextView msg_dialog_btn_ok;
        TextView msg_dialog_btn_3;

        msg_dlg_title = (TextView) view.findViewById(R.id.msg_dlg_title);
        msg_dlg_content = (TextView) view.findViewById(R.id.msg_dlg_content);
        msg_dialog_btn_cancel = (TextView) view.findViewById(R.id.msg_dialog_btn_cancel);
        msg_dialog_btn_ok = (TextView) view.findViewById(R.id.msg_dialog_btn_ok);
        msg_dialog_btn_3 = (TextView) view.findViewById(R.id.msg_dialog_btn_1);
        if (title != null) {
            msg_dlg_title.setText(title);
        } else {
            msg_dlg_title.setVisibility(View.GONE);
        }
        if (content != null) {
            msg_dlg_content.setVisibility(View.VISIBLE);
            msg_dlg_content.setText(content);
        } else {
            msg_dlg_content.setVisibility(View.GONE);
        }
        if (negativeBtnLabel != null) {
            msg_dialog_btn_cancel.setVisibility(View.VISIBLE);
            msg_dialog_btn_cancel.setText(negativeBtnLabel);
        } else {
            msg_dialog_btn_cancel.setVisibility(View.GONE);
        }
        if (positiveBtnLabel != null) {
            msg_dialog_btn_ok.setVisibility(View.VISIBLE);
            msg_dialog_btn_ok.setText(positiveBtnLabel);
        } else {
            msg_dialog_btn_ok.setVisibility(View.GONE);
        }

        if (btnLabel3 != null) {
            msg_dialog_btn_3.setVisibility(View.VISIBLE);
            msg_dialog_btn_3.setText(btnLabel3);
        } else {
            msg_dialog_btn_3.setVisibility(View.GONE);
        }
        if (ngLsn == null) {
            msg_dialog_btn_cancel.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    dialog.dismiss();
                }
            });
        } else {
            msg_dialog_btn_cancel.setOnClickListener(ngLsn);
        }
        if (null == posLsn) {
            msg_dialog_btn_ok.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (null != dialog) {
                        dialog.dismiss();
                    }
                }
            });
        } else {
            msg_dialog_btn_ok.setOnClickListener(posLsn);
        }

        if (null == btn3Lsn) {
            msg_dialog_btn_3.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (null != dialog) {
                        dialog.dismiss();
                    }
                }
            });
        } else {
            msg_dialog_btn_3.setOnClickListener(btn3Lsn);
        }
        return dialog;
    }
}
